<template>
  <div class="recharge-management-page">
    <div class="page-header">
      <h2>充值管理</h2>
      <div class="header-actions">
        <el-button type="primary" @click="showAdminRechargeDialog" :icon="Plus">为用户充值</el-button>
        <el-button @click="refreshData" :icon="Refresh">刷新</el-button>
      </div>
    </div>

    <!-- 搜索筛选 -->
    <el-card class="search-card">
      <el-form :model="searchForm" inline class="search-form">
        <el-form-item label="用户名">
          <el-input
            v-model="searchForm.username"
            placeholder="请输入用户名"
            clearable
            style="width: 200px;"
          />
        </el-form-item>
        
        <el-form-item label="充值金额">
          <el-input-number
            v-model="searchForm.minAmount"
            placeholder="最小金额"
            :min="0"
            :precision="2"
            controls-position="right"
            style="width: 140px;"
          />
          <span style="margin: 0 8px;">-</span>
          <el-input-number
            v-model="searchForm.maxAmount"
            placeholder="最大金额"
            :min="0"
            :precision="2"
            controls-position="right"
            style="width: 140px;"
          />
        </el-form-item>
        
        <el-form-item label="充值类型">
          <el-select v-model="searchForm.rechargeType" placeholder="请选择" clearable>
            <el-option label="手动充值" value="MANUAL" />
            <el-option label="自动充值" value="AUTO" />
            <el-option label="管理员充值" value="ADMIN" />
          </el-select>
        </el-form-item>
        
        <el-form-item label="状态">
          <el-select v-model="searchForm.status" placeholder="请选择" clearable>
            <el-option label="成功" :value="1" />
            <el-option label="失败" :value="0" />
            <el-option label="处理中" :value="2" />
          </el-select>
        </el-form-item>
        
        <el-form-item label="时间范围">
          <el-date-picker
            v-model="searchForm.dateRange"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="YYYY-MM-DD HH:mm:ss"
            value-format="YYYY-MM-DD HH:mm:ss"
          />
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" @click="handleSearch" :icon="Search">搜索</el-button>
          <el-button @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 数据表格 -->
    <el-card class="table-card">
      <el-table
        :data="tableData"
        v-loading="loading"
        stripe
        border
        class="record-table"
      >
        <el-table-column prop="orderNo" label="订单号" min-width="180">
          <template #default="{ row }">
            <el-button type="text" @click="copyToClipboard(row.orderNo)">
              {{ row.orderNo }}
            </el-button>
          </template>
        </el-table-column>
        
        <el-table-column label="用户信息" min-width="150">
          <template #default="{ row }">
            <div class="user-info">
              <div class="username">{{ row.username }}</div>
              <div class="nickname" v-if="row.nickname">{{ row.nickname }}</div>
            </div>
          </template>
        </el-table-column>
        
        <el-table-column prop="rechargeAmount" label="充值金额" width="120" align="right">
          <template #default="{ row }">
            <span class="amount-text">¥{{ row.rechargeAmount }}</span>
          </template>
        </el-table-column>
        
        <el-table-column label="余额变化" width="200" align="center">
          <template #default="{ row }">
            <div class="balance-change">
              <div class="before">充值前：¥{{ row.beforeBalance }}</div>
              <el-icon class="arrow-icon"><ArrowDown /></el-icon>
              <div class="after">充值后：¥{{ row.afterBalance }}</div>
            </div>
          </template>
        </el-table-column>
        
        <el-table-column prop="rechargeType" label="充值类型" width="100">
          <template #default="{ row }">
            <el-tag 
              :type="getRechargeTypeTagType(row.rechargeType)"
              size="small"
            >
              {{ getRechargeTypeName(row.rechargeType) }}
            </el-tag>
          </template>
        </el-table-column>
        
        <el-table-column prop="paymentMethod" label="支付方式" width="120">
          <template #default="{ row }">
            {{ getPaymentMethodName(row.paymentMethod) }}
          </template>
        </el-table-column>
        
        <el-table-column prop="status" label="状态" width="80">
          <template #default="{ row }">
            <el-tag 
              :type="getStatusTagType(row.status)"
              size="small"
            >
              {{ getStatusName(row.status) }}
            </el-tag>
          </template>
        </el-table-column>
        
        <el-table-column label="操作员" width="120">
          <template #default="{ row }">
            <span v-if="row.operatorName">{{ row.operatorName }}</span>
            <span v-else class="text-muted">-</span>
          </template>
        </el-table-column>
        
        <el-table-column prop="remark" label="备注" min-width="150" show-overflow-tooltip />
        
        <el-table-column prop="createTime" label="充值时间" width="160">
          <template #default="{ row }">
            {{ formatDateTime(row.createTime) }}
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagination-container">
        <el-pagination
          v-model:current-page="pagination.current"
          v-model:page-size="pagination.size"
          :page-sizes="[10, 20, 50, 100]"
          :total="pagination.total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>

    <!-- 统计信息 -->
    <el-card class="statistics-card">
      <template #header>
        <div class="card-header">
          <el-icon><DataAnalysis /></el-icon>
          <span>充值统计</span>
        </div>
      </template>
      
      <div class="statistics-content" v-if="statistics">
        <div class="stat-item">
          <div class="stat-label">总充值金额</div>
          <div class="stat-value total">¥{{ statistics.totalAmount || '0.00' }}</div>
        </div>
        <div class="stat-item">
          <div class="stat-label">总充值次数</div>
          <div class="stat-value count">{{ statistics.totalCount || 0 }}次</div>
        </div>
        <div class="stat-item">
          <div class="stat-label">成功率</div>
          <div class="stat-value rate">{{ statistics.successRate || '0.00' }}%</div>
        </div>
        <div class="stat-item">
          <div class="stat-label">今日充值</div>
          <div class="stat-value today">¥{{ statistics.todayAmount || '0.00' }}</div>
        </div>
      </div>
    </el-card>

    <!-- 管理员充值对话框 -->
    <el-dialog
      v-model="adminRechargeDialogVisible"
      title="为用户充值"
      width="500px"
      :close-on-click-modal="false"
    >
      <el-form
        ref="adminRechargeFormRef"
        :model="adminRechargeForm"
        :rules="adminRechargeRules"
        label-width="100px"
      >
        <el-form-item label="选择用户" prop="targetUserId">
          <div class="user-select-container">
            <el-input
              v-model="selectedUserDisplay"
              placeholder="请点击选择用户"
              readonly
              style="width: calc(100% - 100px)"
            >
              <template #prefix>
                <el-icon><User /></el-icon>
              </template>
            </el-input>
            <el-button
              type="primary"
              @click="showUserSelectDialog"
              style="margin-left: 10px"
            >
              选择用户
            </el-button>
            <el-button
              v-if="selectedUser"
              @click="clearSelectedUser"
              style="margin-left: 5px"
            >
              清空
            </el-button>
          </div>
        </el-form-item>
        
        <el-form-item label="充值金额" prop="rechargeAmount">
          <el-input
            v-model="adminRechargeForm.rechargeAmount"
            type="number"
            placeholder="请输入充值金额"
            :min="0.01"
            :step="0.01"
          >
            <template #prefix>¥</template>
          </el-input>
        </el-form-item>
        
        <el-form-item label="快捷金额">
          <div class="quick-amounts">
            <el-button
              v-for="amount in quickAmounts"
              :key="amount"
              @click="setAdminQuickAmount(amount)"
              size="small"
              :type="adminRechargeForm.rechargeAmount == amount.toString() ? 'primary' : ''"
              :plain="adminRechargeForm.rechargeAmount != amount.toString()"
            >
              ¥{{ amount }}
            </el-button>
          </div>
        </el-form-item>
        
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="adminRechargeForm.remark"
            placeholder="请输入充值备注"
            :maxlength="200"
            show-word-limit
          />
        </el-form-item>
      </el-form>
      
      <template #footer>
        <el-button @click="adminRechargeDialogVisible = false">取消</el-button>
        <el-button 
          type="primary" 
          @click="handleAdminRecharge"
          :loading="adminRechargeLoading"
        >
          确认充值
        </el-button>
      </template>
    </el-dialog>

    <!-- 用户选择弹窗 -->
    <el-dialog
      title="选择用户"
      v-model="userSelectDialogVisible"
      width="800px"
      :close-on-click-modal="false"
    >
      <div class="user-select-content">
        <!-- 搜索区域 -->
        <div class="search-section">
          <el-input
            v-model="userSearchKeyword"
            placeholder="请输入用户名、昵称或邮箱搜索"
            clearable
            @input="handleUserSearch"
            style="width: 300px"
          >
            <template #prefix>
              <el-icon><Search /></el-icon>
            </template>
          </el-input>
          <el-button type="primary" @click="loadUserList" :icon="Refresh">刷新</el-button>
        </div>

        <!-- 用户列表表格 -->
        <el-table
          :data="userList"
          v-loading="userListLoading"
          stripe
          border
          highlight-current-row
          @current-change="handleUserRowSelect"
          style="margin-top: 20px"
        >
          <el-table-column type="index" label="序号" width="60" />
          <el-table-column prop="username" label="用户名" width="120" />
          <el-table-column prop="nickname" label="昵称" width="120">
            <template #default="{ row }">
              {{ row.nickname || '无昵称' }}
            </template>
          </el-table-column>
          <el-table-column prop="email" label="邮箱" width="180">
            <template #default="{ row }">
              {{ row.email || '无邮箱' }}
            </template>
          </el-table-column>
          <el-table-column prop="phone" label="手机号" width="120">
            <template #default="{ row }">
              {{ row.phone || '无手机号' }}
            </template>
          </el-table-column>
          <el-table-column prop="status" label="状态" width="80">
            <template #default="{ row }">
              <el-tag :type="row.status === 1 ? 'success' : 'danger'">
                {{ row.status === 1 ? '启用' : '禁用' }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="创建时间" width="160">
            <template #default="{ row }">
              {{ formatDateTime(row.createTime) }}
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页 -->
        <div class="pagination-container">
          <el-pagination
            v-model:current-page="userPagination.current"
            v-model:page-size="userPagination.size"
            :page-sizes="[10, 20, 50, 100]"
            :total="userPagination.total"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleUserPageSizeChange"
            @current-change="handleUserCurrentChange"
          />
        </div>
      </div>

      <template #footer>
        <el-button @click="userSelectDialogVisible = false">取消</el-button>
        <el-button
          type="primary"
          @click="confirmUserSelect"
          :disabled="!selectedUser"
        >
          确认选择
        </el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, nextTick, computed } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Plus, Refresh, Search, ArrowDown, DataAnalysis, User } from '@element-plus/icons-vue'
import request from '../../utils/request'

// 响应式数据
const loading = ref(false)
const tableData = ref([])
const statistics = ref(null)
const adminRechargeDialogVisible = ref(false)
const adminRechargeLoading = ref(false)
const userSearchLoading = ref(false)
const userOptions = ref([])
const adminRechargeFormRef = ref()

// 用户选择弹窗相关
const userSelectDialogVisible = ref(false)
const userListLoading = ref(false)
const userList = ref([])
const selectedUser = ref(null)
const userSearchKeyword = ref('')
const userPagination = reactive({
  current: 1,
  size: 10,
  total: 0
})

// 快捷充值金额
const quickAmounts = [10, 50, 100, 200, 500, 1000]

// 计算属性：选中用户的显示文本
const selectedUserDisplay = computed(() => {
  if (selectedUser.value) {
    return `${selectedUser.value.username} (${selectedUser.value.nickname || '无昵称'})`
  }
  return ''
})

// 搜索表单
const searchForm = reactive({
  username: '',
  minAmount: null,
  maxAmount: null,
  rechargeType: '',
  status: null,
  dateRange: null
})

// 分页参数
const pagination = reactive({
  current: 1,
  size: 20,
  total: 0
})

// 管理员充值表单
const adminRechargeForm = reactive({
  targetUserId: null,
  rechargeAmount: '',
  remark: ''
})

// 管理员充值表单验证规则
const adminRechargeRules = {
  targetUserId: [
    { required: true, message: '请选择用户', trigger: 'change' }
  ],
  rechargeAmount: [
    { required: true, message: '请输入充值金额', trigger: 'blur' },
    { 
      validator: (rule, value, callback) => {
        if (!value || parseFloat(value) <= 0) {
          callback(new Error('充值金额必须大于0'))
        } else if (parseFloat(value) > 100000) {
          callback(new Error('单次充值金额不能超过100,000元'))
        } else {
          callback()
        }
      }, 
      trigger: 'blur' 
    }
  ]
}

// 获取充值记录数据
const fetchData = async () => {
  try {
    loading.value = true
    
    const params = {
      page: pagination.current,
      size: pagination.size
    }
    
    // 添加搜索条件
    if (searchForm.username) {
      params.username = searchForm.username
    }
    if (searchForm.minAmount !== null) {
      params.minAmount = searchForm.minAmount
    }
    if (searchForm.maxAmount !== null) {
      params.maxAmount = searchForm.maxAmount
    }
    if (searchForm.rechargeType) {
      params.rechargeType = searchForm.rechargeType
    }
    if (searchForm.status !== null) {
      params.status = searchForm.status
    }
    if (searchForm.dateRange && searchForm.dateRange.length === 2) {
      params.startTime = searchForm.dateRange[0]
      params.endTime = searchForm.dateRange[1]
    }
    
    const response = await request.get('/admin/recharge/records', { params })
    const result = response.data
    
    tableData.value = result.records || []
    pagination.total = result.total || 0
    
    // 计算统计信息
    calculateStatistics()
  } catch (error) {
    console.error('获取充值记录失败:', error)
    ElMessage.error('获取充值记录失败')
  } finally {
    loading.value = false
  }
}

// 计算统计信息
const calculateStatistics = () => {
  if (!tableData.value || tableData.value.length === 0) {
    statistics.value = {
      totalAmount: '0.00',
      totalCount: 0,
      successRate: '0.00',
      todayAmount: '0.00'
    }
    return
  }
  
  const successRecords = tableData.value.filter(record => record.status === 1)
  const totalAmount = successRecords.reduce((sum, record) => sum + parseFloat(record.rechargeAmount || 0), 0)
  const totalCount = tableData.value.length
  const successCount = successRecords.length
  const successRate = totalCount > 0 ? (successCount / totalCount * 100) : 0
  
  // 计算今日充值金额
  const today = new Date().toDateString()
  const todayRecords = successRecords.filter(record => {
    return new Date(record.createTime).toDateString() === today
  })
  const todayAmount = todayRecords.reduce((sum, record) => sum + parseFloat(record.rechargeAmount || 0), 0)
  
  statistics.value = {
    totalAmount: totalAmount.toFixed(2),
    totalCount: totalCount,
    successRate: successRate.toFixed(2),
    todayAmount: todayAmount.toFixed(2)
  }
}

// 搜索用户
const searchUsers = async (query) => {
  if (!query || query.trim().length < 2) {
    userOptions.value = []
    return
  }

  try {
    userSearchLoading.value = true
    const response = await request.get('/admin/recharge/users/search', {
      params: { keyword: query.trim(), limit: 20 }
    })
    userOptions.value = response.data || []
  } catch (error) {
    console.error('搜索用户失败:', error)
    ElMessage.error('搜索用户失败')
    userOptions.value = []
  } finally {
    userSearchLoading.value = false
  }
}

// 处理用户选择清空
const handleUserSelectClear = () => {
  userOptions.value = []
}

// 显示用户选择弹窗
const showUserSelectDialog = () => {
  userSelectDialogVisible.value = true
  loadUserList()
}

// 加载用户列表
const loadUserList = async () => {
  try {
    userListLoading.value = true
    const params = {
      page: userPagination.current,
      size: userPagination.size
    }

    // 只有当搜索关键词不为空时才添加keyword参数
    if (userSearchKeyword.value && userSearchKeyword.value.trim()) {
      params.keyword = userSearchKeyword.value.trim()
    }

    console.log('发送用户搜索请求，参数:', params)
    const response = await request.get('/admin/recharge/users/search', { params })
    console.log('用户搜索响应:', response)
    const result = response.data
    userList.value = result.records || []
    userPagination.total = result.total || 0
  } catch (error) {
    console.error('获取用户列表失败:', error)
    ElMessage.error('获取用户列表失败')
  } finally {
    userListLoading.value = false
  }
}

// 处理用户搜索
const handleUserSearch = () => {
  userPagination.current = 1
  loadUserList()
}

// 处理用户行选择
const handleUserRowSelect = (row) => {
  selectedUser.value = row
}

// 确认选择用户
const confirmUserSelect = () => {
  if (selectedUser.value) {
    adminRechargeForm.targetUserId = selectedUser.value.id
    userSelectDialogVisible.value = false
  }
}

// 清空选中的用户
const clearSelectedUser = () => {
  selectedUser.value = null
  adminRechargeForm.targetUserId = null
}

// 用户列表分页处理
const handleUserPageSizeChange = (size) => {
  userPagination.size = size
  userPagination.current = 1
  loadUserList()
}

const handleUserCurrentChange = (current) => {
  userPagination.current = current
  loadUserList()
}

// 显示管理员充值对话框
const showAdminRechargeDialog = () => {
  resetAdminRechargeForm()
  adminRechargeDialogVisible.value = true
}

// 设置快捷金额
const setAdminQuickAmount = (amount) => {
  adminRechargeForm.rechargeAmount = amount.toString()
  // 手动触发表单验证
  nextTick(() => {
    adminRechargeFormRef.value?.validateField('rechargeAmount')
  })
}

// 处理管理员充值
const handleAdminRecharge = async () => {
  try {
    await adminRechargeFormRef.value.validate()

    if (!selectedUser.value) {
      ElMessage.error('请选择要充值的用户')
      return
    }

    const targetUserName = selectedUser.value.username

    await ElMessageBox.confirm(
      `确认为用户 "${targetUserName}" 充值 ¥${adminRechargeForm.rechargeAmount} 元吗？`,
      '确认充值',
      {
        type: 'warning',
        confirmButtonText: '确认充值',
        cancelButtonText: '取消'
      }
    )

    adminRechargeLoading.value = true

    const response = await request.post('/admin/recharge', {
      targetUserId: adminRechargeForm.targetUserId,
      rechargeAmount: parseFloat(adminRechargeForm.rechargeAmount),
      remark: adminRechargeForm.remark || '管理员充值'
    })

    ElMessage.success('充值成功！订单号：' + response.data)

    // 关闭对话框并刷新数据
    adminRechargeDialogVisible.value = false
    await fetchData()
  } catch (error) {
    if (error !== 'cancel') {
      console.error('管理员充值失败:', error)
      ElMessage.error('充值失败：' + (error.response?.data?.message || error.message))
    }
  } finally {
    adminRechargeLoading.value = false
  }
}

// 重置管理员充值表单
const resetAdminRechargeForm = () => {
  adminRechargeFormRef.value?.resetFields()
  adminRechargeForm.targetUserId = null
  adminRechargeForm.rechargeAmount = ''
  adminRechargeForm.remark = ''
  selectedUser.value = null
  userOptions.value = []
}

// 搜索处理
const handleSearch = () => {
  pagination.current = 1
  fetchData()
}

// 重置搜索
const resetSearch = () => {
  Object.keys(searchForm).forEach(key => {
    if (Array.isArray(searchForm[key])) {
      searchForm[key] = null
    } else if (typeof searchForm[key] === 'number') {
      searchForm[key] = null
    } else {
      searchForm[key] = ''
    }
  })
  handleSearch()
}

// 分页处理
const handleSizeChange = (newSize) => {
  pagination.size = newSize
  pagination.current = 1
  fetchData()
}

const handleCurrentChange = (newPage) => {
  pagination.current = newPage
  fetchData()
}

// 刷新数据
const refreshData = () => {
  fetchData()
}

// 格式化日期时间
const formatDateTime = (dateTime) => {
  if (!dateTime) return ''
  return new Date(dateTime).toLocaleString('zh-CN')
}

// 获取充值类型名称
const getRechargeTypeName = (type) => {
  switch (type) {
    case 'MANUAL': return '手动充值'
    case 'AUTO': return '自动充值'
    case 'ADMIN': return '管理员充值'
    default: return type || '未知'
  }
}

// 获取充值类型标签类型
const getRechargeTypeTagType = (type) => {
  switch (type) {
    case 'MANUAL': return 'primary'
    case 'AUTO': return 'success'
    case 'ADMIN': return 'warning'
    default: return 'info'
  }
}

// 获取支付方式名称
const getPaymentMethodName = (method) => {
  switch (method) {
    case 'BALANCE': return '余额支付'
    case 'ALIPAY': return '支付宝'
    case 'WECHAT': return '微信支付'
    default: return method || '未知'
  }
}

// 获取状态名称
const getStatusName = (status) => {
  switch (status) {
    case 1: return '成功'
    case 0: return '失败'
    case 2: return '处理中'
    default: return '未知'
  }
}

// 获取状态标签类型
const getStatusTagType = (status) => {
  switch (status) {
    case 1: return 'success'
    case 0: return 'danger'
    case 2: return 'warning'
    default: return 'info'
  }
}

// 复制到剪贴板
const copyToClipboard = async (text) => {
  try {
    await navigator.clipboard.writeText(text)
    ElMessage.success('订单号已复制到剪贴板')
  } catch (error) {
    console.error('复制失败:', error)
    ElMessage.error('复制失败')
  }
}

// 页面加载时获取数据
onMounted(() => {
  fetchData()
})
</script>

<style scoped>
.recharge-management-page {
  padding: 20px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.page-header h2 {
  margin: 0;
  color: #333;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.search-card {
  margin-bottom: 20px;
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.table-card {
  margin-bottom: 20px;
}

.record-table {
  width: 100%;
}

.user-info {
  line-height: 1.4;
}

.username {
  font-weight: 600;
  color: #333;
}

.nickname {
  font-size: 12px;
  color: #666;
  margin-top: 2px;
}

.amount-text {
  font-weight: 600;
  color: #67c23a;
}

.balance-change {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 12px;
}

.before {
  color: #909399;
  margin-bottom: 2px;
}

.arrow-icon {
  color: #409eff;
  margin: 2px 0;
}

.after {
  color: #67c23a;
  font-weight: 600;
  margin-top: 2px;
}

.text-muted {
  color: #999;
}

.pagination-container {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

.statistics-card {
  margin-top: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  font-weight: 600;
  color: #333;
}

.card-header .el-icon {
  margin-right: 8px;
  font-size: 18px;
}

.statistics-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.stat-item {
  text-align: center;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
}

.stat-label {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
}

.stat-value.total {
  color: #67c23a;
}

.stat-value.count {
  color: #409eff;
}

.stat-value.rate {
  color: #e6a23c;
}

.stat-value.today {
  color: #f56c6c;
}

.quick-amounts {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.user-option {
  display: flex;
  flex-direction: column;
  line-height: 1.4;
}

.user-main {
  font-weight: 600;
  color: #333;
}

.user-sub {
  font-size: 12px;
  color: #666;
  margin-top: 2px;
}

.user-select-container {
  display: flex;
  align-items: center;
  width: 100%;
}

.user-select-content {
  padding: 10px 0;
}

.search-section {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.pagination-container {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

@media (max-width: 768px) {
  .search-form {
    flex-direction: column;
  }
  
  .statistics-content {
    grid-template-columns: 1fr;
  }
  
  .header-actions {
    flex-direction: column;
  }
}
</style>